package com.bruce.algorithm.sort;

import java.util.Arrays;

/**
 * 冒泡排序
 * <br>CreateDate  2021/10/27 19:48:28
 *
 * @author luotuan
 * @version 1.0.0
 */
public class BubblingSort {
    public static void main(String[] args) {
        int[] array = {1,3,2,6,8,10,20,11,9};
        System.out.println(Arrays.toString(sort(array)));
    }
    public static int[] sort(int[] array){
        if(array.length<=1){
            return array;
        }
        int len = array.length;
        for(int i=0;i<len;i++){
            boolean exchange = false;
            for(int j=0;j<len-1;j++){
                if(array[j]>array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    exchange = true;
                }
            }
            if(!exchange){
                break;
            }
        }
        return array;
    }

}
